using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using And.Shp.Common.ServiceLocation;
using Uportal.Shp.Core.Services;

namespace Uportal.Shp.Core.Features.ServiceLocator
{

    [Guid("de711d3e-1470-47b7-b6df-05c576f4ec29")]
    public class ServiceLocatorEventReceiver : SPFeatureReceiver
    {
        private static readonly ILogger Logger = SL.GetCurrent().GetInstance<ILogger>();

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            var web = properties.Feature.Parent as SPWeb;
            if (web == null)
            {
                Logger.Error("ServiceLocatorEventReceiver FeatureActivated: web is null");
                return;
            }

            try
            {
                Settings.Save(web.Url, Settings.GetDefault());
            }
            catch (Exception ex)
            {
                Logger.Exception(ex);
                throw;
            }
        }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            var web = properties.Feature.Parent as SPWeb;
            if (web == null)
            {
                Logger.Error("ServiceLocatorEventReceiver FeatureDeactivating: web is null");
                return;
            }

            try
            {
            }
            catch (Exception ex)
            {
                Logger.Exception(ex);
                throw;
            }
        }
    }
}
